class Solution {
public:
    bool isValid(string s) {
        map<char,char>mp;
        mp[')']='(';
        mp['}']='{';
        mp[']']='[';
        stack<char>stk;
        for(int i=0;i<s.length();i++){
            if(stk.empty() || stk.top()!=mp[s[i]]){
                stk.push(s[i]);
            }else{
                stk.pop();
            }
        }
        if(stk.empty()){
            return true;
        }
        return false;
    }
};